package com.lzs.collection.Set;

import lombok.Data;

import java.util.HashSet;
import java.util.Objects;

public class HashSetExercise02 {
    public static void main(String[] args) {
        HashSet<Object> set = new HashSet<>();
        set.add(new Employee1("lzs", 6000, new MyDate(1990,3,4)));
        set.add(new Employee1("lzs", 6000, new MyDate(1990,2,4)));
        set.add(new Employee1("lzs", 6000, new MyDate(1990,3,4)));
        System.out.println(set);
    }
}

@Data
class MyDate {
    int year;
    int month;
    int day;

  public MyDate(int year, int month, int day) {
      this.year = year;
      this.month = month;
      this.day = day;
  }

    @Override
    public String toString() {
        return String.format("%d/%d/%d", year, month, day);
    }

    @Override
    public int hashCode() {
        return Objects.hash(year, month, day);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyDate myDate = (MyDate) o;
        return year == myDate.year && month == myDate.month && day == myDate.day;
    }


}

@Data
class Employee1 {
    private String name;
    private int salary;
    private MyDate birthday;
    public Employee1(String name, int salary, MyDate birthday) {
        this.name = name;
        this.salary = salary;
        this.birthday = birthday;
    }
    @Override
    public int hashCode() {
        return Objects.hash(name, salary, birthday);
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee1 employee1 = (Employee1) o;
        return Objects.equals(name,employee1.name)&&Objects.equals(birthday,employee1.birthday);
    }
}

